<template>
    <div class="list">
        <van-pull-refresh class="list-pull" v-model="isLoading" @refresh="onRefresh">
            <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
            >
                <div class="item" v-for="(item,index) in list" :key="index">
                    <Article :state="state" :item="item" :allCheck="select" @select="getSelect"></Article>
                </div>
            </van-list>
        </van-pull-refresh>
    </div>
</template>

<script>
import Article from './Article'
import { Toast } from 'vant';
export default {
    name:"list",
    props:{
        list:{},
        state:{
            type:Boolean
        },
        select:{
            type:Boolean
        },
        listChange:{
            type:Object
        },
        finished:{
            type:Boolean
        }
    },
    components:{
        Article
    },
    data(){
        return {
            loading: false,
            selectList: [],
            isLoading: true
        }
    },
    methods:{
        onLoad() {
            this.$emit('onload')
        },
        getSelect(res) {
            const id = this.selectList.indexOf(res)
            if(id > -1){
                this.selectList.splice(id,1)
            }else{
                this.selectList.push(res)
            }
            this.$emit('select',this.selectList)
            console.log(this.selectList)
        },
        onRefresh() {
            this.$emit('onRefresh')
            setTimeout(() => {
                Toast('刷新成功');
                this.isLoading = false;
            }, 1000);
        }
    },
}
</script>

<style scoped>
.list{
    height:calc(100vh - 0.92rem);
}
.list .list-pull{
    height:100%;
}
</style>